/*
 * BuildingUnit.hpp
 *
 *  Created on: 2013-1-14
 *      Author: heqiu
 */

#ifndef BUILDINGUNIT_HPP_
#define BUILDINGUNIT_HPP_

#include "mycomm.h"
/*
 * 建筑物体有id 取值 [1,1000000]
 * 路没有id。一个点，就是一条路。必须相邻的路，才能行走。
 * 路的id取值
 * [1000001-1000010]
 */

//定义路的id
typedef enum {
	B_WAY_begin = 1000001,
	B_WAY_1 = 1000001, //土路
	B_WAY_2 = 1000002, //砖路
	B_WAY_3 = 1000003, //高速路
	B_WAY_end = 1000010,
} WayType;

class BuildingUnit {
public:
	static bool isWay(uint32_t uiId) {
		if (uiId >= 1000001 && uiId <= 1000010) {
			return true;
		}
		return false;
	}
	static uint32_t getWayId(uint32_t uiType) {
		if (uiType == 2) {
			return B_WAY_2;
		}
		if (uiType == 3) {
			return B_WAY_3;
		}
		return B_WAY_1;
	}
	BuildingUnit() {
		m_xLen = 0;
		m_yLen = 0;
		m_iId = 0;
		m_iType = 0;
		m_pSDL_Surface = NULL;
	}
	void init(uint32_t uiXLen, uint32_t uiYLen) {
		m_xLen = uiXLen;
		m_yLen = uiYLen;
	}
	bool loadImage(string & sName) {
		SDL_Surface* loadedImage = NULL;
		SDL_Surface* optimizedImage = NULL;
		loadedImage = IMG_Load(sName.c_str());
		if (loadedImage != NULL) {
			optimizedImage = SDL_DisplayFormat(loadedImage);
			SDL_FreeSurface(loadedImage);
			if (optimizedImage != NULL) {
				SDL_SetColorKey(optimizedImage, SDL_SRCCOLORKEY,
						SDL_MapRGB(optimizedImage->format, 0, 0xFF, 0xFF));
			}
		}
		m_pSDL_Surface = optimizedImage;
		return false;
	}
	MyPoint m_pPos;
	uint32_t m_xLen;
	uint32_t m_yLen;
	uint32_t m_iId;	//建筑标号
	uint32_t m_iType;	//建筑类别
	SDL_Surface* m_pSDL_Surface;
};

#endif /* BUILDINGUNIT_HPP_ */
